#
# Cookbook Name:: db2
# Recipe:: client
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

include_recipe "gitclientsetup"
cuser = node['chef']['user']
cgroup = node['chef']['group']

startinstr "db2client"

# Download the DB2 install package
directory "/tmp/db2" do
  user cuser
  action :create
end

bash "fetchandunzipDB2" do
  user cuser
  cwd "/tmp/db2"
  creates "/tmp/fetchandunzipDB2.done"
  code <<-EOH
    set -e
    scp #{node[:common][:scp_repo]}/#{node[:db2][:filepath]} .
    tar xvzf $(basename #{node[:db2][:filepath]})
    touch /tmp/fetchandunzipDB2.done
  EOH
end

# Update the silent install template
template "/tmp/db2/server/mydb2client.rsp" do
  source "db2client.rsp.erb"
  owner cuser
  group cgroup
  variables(:installLoc => node[:db2][:installDir], :db2Pass => node[:db2][:password])
  action :create
end

# Install the db2 client
bash "installdb2client" do
  user "root"
  cwd "/tmp/db2/server"
  code <<-EOH
  ./db2setup -r /tmp/db2/server/mydb2client.rsp
  EOH
  not_if "test -d #{node[:db2][:installDir]}"  
end

stopinstr "db2client"
